package fr.iut2.sil4.data;

import java.io.Serializable;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import org.apache.torque.TorqueException;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.BooleanKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.om.ColumnAccessByName;
import org.apache.torque.criteria.Criteria;
import org.apache.torque.util.Transaction;
import org.apache.commons.lang.ObjectUtils;


/**
 * Cours Table
 *
 * This class was autogenerated by Torque on:
 *
 * [Mon Jan 20 15:56:22 CET 2014]
 *
 * You should not use this class directly.  It should not even be
 * extended; all references should be to Cours
 */
public abstract class BaseCours 
    implements Persistent, Serializable, ColumnAccessByName
{
    /** Serial version */
    private static final long serialVersionUID = 1390229782805L;



    /** Cours Id */
    private int coursId = 0;

    /** Cours start date and time */
    private java.util.Date startTime = null;

    /** Cours end date and time */
    private java.util.Date endTime = null;

    /** Cours location */
    private String salle = null;

    /** Cours matiere */
    private int matiereId = 0;

    /** Enseignant teaching the cours */
    private int enseignantId = 0;

    /** Cours groupe */
    private int groupeId = 0;

    /** Whether this object was modified after loading or after last save. */
    private boolean modified = true;

    /** 
     * Whether this object was loaded from the database or already saved 
     * (false) or whether it is not yet in the database(true).
     */
    private boolean isNew = true;

    /** Flag which indicates whether this object is currently saving. */
    private boolean saving = false;

    /** 
     * Flag which indicates whether this object is currently loaded
     * from the database. 
     */
    private boolean loading = false;

    /** 
     * Flag which indicates whether this object was deleted from the database.
     * Note that this flags does not always display the current database state,
     * there is no magical connection between this flag and the database.
     */
    private boolean deleted = false;

    /** Defines the aMatiere field. */
    private Matiere aMatiere = null;

    /** Defines the aEnseignant field. */
    private Enseignant aEnseignant = null;

    /** Defines the aGroupe field. */
    private Groupe aGroupe = null;



    /** Defines the collAbsences field. */
    protected List<Absence> collAbsences = null;



    /**
     * Get the value of coursId.
     * The field is described as follows: 
     * Cours Id
     *
     * @return int
     */
    public int getCoursId() 
    {
        
        return coursId;
    }

    /**
     * Set the value of coursId.
     * The field is described as follows: 
     * Cours Id
     *
     * @param v new value
     */
    public void setCoursId(int v)
    {
        if (this.coursId != v)
        {
            setModified(true);
        }

        this.coursId = v;

        // update associated objects in collAbsences 
        if (collAbsences != null)
        {
            for (int i = 0; i < collAbsences.size(); i++)
            {
                ((Absence) collAbsences.get(i))
                        .setCoursId(v);
            }
        }

    }
    
    /**
     * Get the value of startTime.
     * The field is described as follows: 
     * Cours start date and time
     *
     * @return java.util.Date
     */
    public java.util.Date getStartTime() 
    {
        
        return startTime;
    }

    /**
     * Set the value of startTime.
     * The field is described as follows: 
     * Cours start date and time
     *
     * @param v new value
     */
    public void setStartTime(java.util.Date v)
    {
        if (!ObjectUtils.equals(this.startTime, v))
        {
            setModified(true);
        }

        this.startTime = v;


    }
    
    /**
     * Get the value of endTime.
     * The field is described as follows: 
     * Cours end date and time
     *
     * @return java.util.Date
     */
    public java.util.Date getEndTime() 
    {
        
        return endTime;
    }

    /**
     * Set the value of endTime.
     * The field is described as follows: 
     * Cours end date and time
     *
     * @param v new value
     */
    public void setEndTime(java.util.Date v)
    {
        if (!ObjectUtils.equals(this.endTime, v))
        {
            setModified(true);
        }

        this.endTime = v;


    }
    
    /**
     * Get the value of salle.
     * The field is described as follows: 
     * Cours location
     *
     * @return String
     */
    public String getSalle() 
    {
        
        return salle;
    }

    /**
     * Set the value of salle.
     * The field is described as follows: 
     * Cours location
     *
     * @param v new value
     */
    public void setSalle(String v)
    {
        if (!ObjectUtils.equals(this.salle, v))
        {
            setModified(true);
        }

        this.salle = v;


    }
    
    /**
     * Get the value of matiereId.
     * The field is described as follows: 
     * Cours matiere
     *
     * @return int
     */
    public int getMatiereId() 
    {
        
        return matiereId;
    }

    /**
     * Set the value of matiereId.
     * The field is described as follows: 
     * Cours matiere
     *
     * @param v new value
     */
    public void setMatiereId(int v)
    {
        if (this.matiereId != v)
        {
            setModified(true);
        }

        this.matiereId = v;
        if (aMatiere != null && aMatiere.getMatiereId() != v)
        {
            aMatiere = null;
        }


    }
    
    /**
     * Get the value of enseignantId.
     * The field is described as follows: 
     * Enseignant teaching the cours
     *
     * @return int
     */
    public int getEnseignantId() 
    {
        
        return enseignantId;
    }

    /**
     * Set the value of enseignantId.
     * The field is described as follows: 
     * Enseignant teaching the cours
     *
     * @param v new value
     */
    public void setEnseignantId(int v)
    {
        if (this.enseignantId != v)
        {
            setModified(true);
        }

        this.enseignantId = v;
        if (aEnseignant != null && aEnseignant.getEnseignantId() != v)
        {
            aEnseignant = null;
        }


    }
    
    /**
     * Get the value of groupeId.
     * The field is described as follows: 
     * Cours groupe
     *
     * @return int
     */
    public int getGroupeId() 
    {
        
        return groupeId;
    }

    /**
     * Set the value of groupeId.
     * The field is described as follows: 
     * Cours groupe
     *
     * @param v new value
     */
    public void setGroupeId(int v)
    {
        if (this.groupeId != v)
        {
            setModified(true);
        }

        this.groupeId = v;
        if (aGroupe != null && aGroupe.getGroupeId() != v)
        {
            aGroupe = null;
        }


    }
    

    /**
     * Returns whether the object has ever been saved.  This will
     * be false, if the object was retrieved from storage or was created
     * and then saved.
     *
     * @return true, if the object has never been persisted.
     */
    public boolean isNew()
    {
        return isNew;
    }

    /**
     * Sets whether the object has ever been saved.
     *
     * @param isNew true if the object has never been saved, false otherwise.
     */
    public void setNew(boolean isNew)
    {
        this.isNew = isNew;
    }

    /**
     * Returns whether the object has been modified.
     *
     * @return True if the object has been modified.
     */
    public boolean isModified()
    {
        return modified;
    }

    /**
     * Sets whether the object has been modified.
     *
     * @param modified true if the object has been modified, false otherwise.
     */
    public void setModified(boolean modified)
    {
        this.modified = modified;
    }

    /**
     * Sets the modified state for the object to be false.
     */
    public void resetModified()
    {
        modified = false;
    }


    /**
     * Returns whether this object is currently saving.
     *
     * @return true if this object is currently saving, false otherwise.
     */
    public boolean isSaving()
    {
        return saving;
    }

    /**
     * Sets whether this object is currently saving.
     *
     * @param saving true if this object is currently saving, false otherwise.
     */
    public void setSaving(boolean saving)
    {
        this.saving = saving;
    }


    /**
     * Returns whether this object is currently being loaded from the database.
     *
     * @return true if this object is currently loading, false otherwise.
     */
    public boolean isLoading()
    {
        return loading;
    }

    /**
     * Sets whether this object is currently being loaded from the database.
     *
     * @param loading true if this object is currently loading, false otherwise.
     */
    public void setLoading(boolean loading)
    {
        this.loading = loading;
    }


    /**
     * Returns whether this object was deleted from the database.
     * Note that this getter does not automatically reflect database state,
     * it will be set to true by Torque if doDelete() was called with this 
     * object. Bulk deletes and deletes via primary key do not change
     * this flag. Also, if doDelete() was called on an object which does
     * not exist in the database, the deleted flag is set to true even if
     * it was not deleted.
     *
     * @return true if this object was deleted, false otherwise.
     */
    public boolean isDeleted()
    {
        return deleted;
    }

    /**
     * Sets whether this object was deleted from the database.
     *
     * @param deleted true if this object was deleted, false otherwise.
     */
    public void setDeleted(boolean deleted)
    {
        this.deleted = deleted;
    }


    /**
     * Returns the associated Matiere object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Matiere object
     * @throws TorqueException when reading from the database fails.
     */
    public Matiere getMatiere()
        throws TorqueException
    {
        if (aMatiere == null && this.matiereId != 0)
        {
            aMatiere = fr.iut2.sil4.data.MatierePeer.retrieveByPK(SimpleKey.keyFor(this.matiereId));
        }
        return aMatiere;
    }

    /**
     * Return the associated Matiere object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Matiere object
     * @throws TorqueException
     */
    public Matiere getMatiere(Connection connection)
        throws TorqueException
    {
        if (aMatiere == null && this.matiereId != 0)
        {
            aMatiere = fr.iut2.sil4.data.MatierePeer.retrieveByPK(SimpleKey.keyFor(this.matiereId), connection);
        }
        return aMatiere;
    }


    /**
     * Declares an association between this object and a Matiere object
     *
     * @param v Matiere
     */
    public void setMatiere(Matiere v)
    {
        if (v == null)
        {
            setMatiereId(0);
        }
        else
        {
            setMatiereId(v.getMatiereId());
        }
        aMatiere = v;
    }
    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setMatiereKey(ObjectKey key) throws TorqueException
    {
       
        setMatiereId(((NumberKey) key).intValue());
     }

    /**
     * Returns the associated Enseignant object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Enseignant object
     * @throws TorqueException when reading from the database fails.
     */
    public Enseignant getEnseignant()
        throws TorqueException
    {
        if (aEnseignant == null && this.enseignantId != 0)
        {
            aEnseignant = fr.iut2.sil4.data.EnseignantPeer.retrieveByPK(SimpleKey.keyFor(this.enseignantId));
        }
        return aEnseignant;
    }

    /**
     * Return the associated Enseignant object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Enseignant object
     * @throws TorqueException
     */
    public Enseignant getEnseignant(Connection connection)
        throws TorqueException
    {
        if (aEnseignant == null && this.enseignantId != 0)
        {
            aEnseignant = fr.iut2.sil4.data.EnseignantPeer.retrieveByPK(SimpleKey.keyFor(this.enseignantId), connection);
        }
        return aEnseignant;
    }


    /**
     * Declares an association between this object and a Enseignant object
     *
     * @param v Enseignant
     */
    public void setEnseignant(Enseignant v)
    {
        if (v == null)
        {
            setEnseignantId(0);
        }
        else
        {
            setEnseignantId(v.getEnseignantId());
        }
        aEnseignant = v;
    }
    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setEnseignantKey(ObjectKey key) throws TorqueException
    {
       
        setEnseignantId(((NumberKey) key).intValue());
     }

    /**
     * Returns the associated Groupe object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Groupe object
     * @throws TorqueException when reading from the database fails.
     */
    public Groupe getGroupe()
        throws TorqueException
    {
        if (aGroupe == null && this.groupeId != 0)
        {
            aGroupe = fr.iut2.sil4.data.GroupePeer.retrieveByPK(SimpleKey.keyFor(this.groupeId));
        }
        return aGroupe;
    }

    /**
     * Return the associated Groupe object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Groupe object
     * @throws TorqueException
     */
    public Groupe getGroupe(Connection connection)
        throws TorqueException
    {
        if (aGroupe == null && this.groupeId != 0)
        {
            aGroupe = fr.iut2.sil4.data.GroupePeer.retrieveByPK(SimpleKey.keyFor(this.groupeId), connection);
        }
        return aGroupe;
    }


    /**
     * Declares an association between this object and a Groupe object
     *
     * @param v Groupe
     */
    public void setGroupe(Groupe v)
    {
        if (v == null)
        {
            setGroupeId(0);
        }
        else
        {
            setGroupeId(v.getGroupeId());
        }
        aGroupe = v;
    }
    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setGroupeKey(ObjectKey key) throws TorqueException
    {
       
        setGroupeId(((NumberKey) key).intValue());
     }



    /**
     * Initializes the cache collAbsences for referenced objects.
     * This, means, if collAbsences is null when this operation is called, it is
     * initialized with an empty collection, otherwise it remains unchanged. 
     *
     * @return the (possibly new) content of the field collAbsences, not null.
     */
    public List<Absence> initAbsences()
    {
        if (collAbsences == null)
        {
            collAbsences = new ArrayList<Absence>();
        }
        return collAbsences;
    }

    /**
     * Checks whether the cache collAbsences for referenced objects has either been
     * loaded from the database or has been manually initialized.
     */
    public boolean isAbsencesInitialized()
    {
        return (collAbsences != null);
    }


    /**
     * Method called to associate a Absence object to this object
     * through the collAbsences foreign key attribute.
     * If the associated objects were not retrieved before
     * and this object is not new, the associated objects are retrieved
     * from the database before adding the <code>toAdd</code> object.
     *
     * @param toAdd the object to add to the associated objects, not null.
     *
     * @throws TorqueException if retrieval of the associated objects fails.
     * @throws NullPointerException if toAdd is null.
     */
    public void addAbsence(Absence toAdd)
        throws TorqueException
    {
        toAdd.setCours((Cours) this);
        getAbsences().add(toAdd);
    }

    /**
     * Method called to associate a Absence object to this object
     * through the collAbsences foreign key attribute using connection.
     *
     * @param l Absence
     * @throws TorqueException
     */
    public void addAbsence(Absence l, Connection con) throws TorqueException
    {
        getAbsences(con).add(l);
        l.setCours((Cours) this);
    }
    
    /**
     * The criteria used to select the current contents of collAbsences
     */
    private Criteria lastAbsenceCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getAbsences(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List<Absence> getAbsences()
        throws TorqueException
    {
        if (collAbsences == null)
        {
            collAbsences = getAbsences(new Criteria());
        }
        return collAbsences;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this BaseCours has previously
     * been saved, it will retrieve related collAbsences from storage.
     * If this BaseCours is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List<Absence> getAbsences(Criteria criteria) throws TorqueException
    {
        if (collAbsences == null)
        {
            if (isNew())
            {
               initAbsences();
            }
            else
            {
                criteria.and(fr.iut2.sil4.data.AbsencePeer.COURS_ID, getCoursId() );
                collAbsences = fr.iut2.sil4.data.AbsencePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.and(fr.iut2.sil4.data.AbsencePeer.COURS_ID, getCoursId() );
                if (lastAbsenceCriteria == null 
                        || !lastAbsenceCriteria.equals(criteria))
                {
                    collAbsences = fr.iut2.sil4.data.AbsencePeer.doSelect(criteria);
                }
            }
        }
        lastAbsenceCriteria = criteria;

        return collAbsences;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getAbsences(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List<Absence> getAbsences(Connection con) throws TorqueException
    {
        if (collAbsences == null)
        {
            collAbsences = getAbsences(new Criteria(), con);
        }
        return collAbsences;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this BaseCours has previously
     * been saved, it will retrieve the related Absence Objects 
     * from storage.
     * If this BaseCours is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List<Absence> getAbsences(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collAbsences == null)
        {
            if (isNew())
            {
               initAbsences();
            }
            else
            {
                criteria.and(fr.iut2.sil4.data.AbsencePeer.COURS_ID, getCoursId());
                collAbsences = fr.iut2.sil4.data.AbsencePeer.doSelect(criteria, con);
            }
        }
        else
        {
             // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.and(fr.iut2.sil4.data.AbsencePeer.COURS_ID, getCoursId());
                if (!lastAbsenceCriteria.equals(criteria))
                {
                    collAbsences = fr.iut2.sil4.data.AbsencePeer.doSelect(criteria, con);
                }
            }
        }
        lastAbsenceCriteria = criteria;

        return collAbsences;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this BaseCours is new, it will return
     * an empty collection; or if this thisObjectClassName has previously
     * been saved, it will retrieve the related objects from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can change the access modifier to public
     * by overriding this method in the child class.
     */
    protected List<Absence> getAbsencesJoinCours(Criteria criteria) throws TorqueException
    {
        return getAbsencesJoinCours(criteria, null);
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this BaseCours is new, it will return
     * an empty collection; or if this BaseCours has previously
     * been saved, it will retrieve the related objects from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can change the access modifier to public
     * by overriding this method in the child class.
     */
    protected List<Absence> getAbsencesJoinCours(Criteria criteria, Connection connection)
        throws TorqueException
    {
        if (collAbsences == null)
        {
            if (isNew())
            {
                initAbsences();
            }
            else
            {
                criteria.and(fr.iut2.sil4.data.AbsencePeer.COURS_ID, getCoursId() );
                collAbsences = fr.iut2.sil4.data.AbsencePeer.doSelectJoinCours(criteria, connection);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.and(fr.iut2.sil4.data.AbsencePeer.COURS_ID, getCoursId() );
            if (!lastAbsenceCriteria.equals(criteria))
            {
                collAbsences = fr.iut2.sil4.data.AbsencePeer.doSelectJoinCours(criteria, connection);
            }
        }
        lastAbsenceCriteria = criteria;

        return collAbsences;
    }




    private static final List<String> FIELD_NAMES;

    static
    {
        List<String> fieldNames
                = new ArrayList<String>();
        fieldNames.add("CoursId");
        fieldNames.add("StartTime");
        fieldNames.add("EndTime");
        fieldNames.add("Salle");
        fieldNames.add("MatiereId");
        fieldNames.add("EnseignantId");
        fieldNames.add("GroupeId");
        FIELD_NAMES = Collections.unmodifiableList(fieldNames);
    }

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static List<String> getFieldNames()
    {
        return FIELD_NAMES;
    }

    /**
     * Retrieves a field from the object by field (Java) name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
        if (name.equals("CoursId"))
        {
            return new Integer(getCoursId());
        }
        if (name.equals("StartTime"))
        {
            return getStartTime();
        }
        if (name.equals("EndTime"))
        {
            return getEndTime();
        }
        if (name.equals("Salle"))
        {
            return getSalle();
        }
        if (name.equals("MatiereId"))
        {
            return new Integer(getMatiereId());
        }
        if (name.equals("EnseignantId"))
        {
            return new Integer(getEnseignantId());
        }
        if (name.equals("GroupeId"))
        {
            return new Integer(getGroupeId());
        }
        return null;
    }

    /**
     * Set a field in the object by field (Java) name.
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByName(String name, Object value)
        throws TorqueException, IllegalArgumentException
    {
        if (name.equals("CoursId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setCoursId(((Integer) value).intValue());
            return true;
        }
        if (name.equals("StartTime"))
        {
            // Object fields can be null
            if (value != null && ! java.util.Date.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setStartTime((java.util.Date) value);
            return true;
        }
        if (name.equals("EndTime"))
        {
            // Object fields can be null
            if (value != null && ! java.util.Date.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setEndTime((java.util.Date) value);
            return true;
        }
        if (name.equals("Salle"))
        {
            // Object fields can be null
            if (value != null && ! String.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setSalle((String) value);
            return true;
        }
        if (name.equals("MatiereId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setMatiereId(((Integer) value).intValue());
            return true;
        }
        if (name.equals("EnseignantId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setEnseignantId(((Integer) value).intValue());
            return true;
        }
        if (name.equals("GroupeId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setGroupeId(((Integer) value).intValue());
            return true;
        }
        return false;
    }

    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
        if (name.equals(fr.iut2.sil4.data.CoursPeer.COURS_ID))
        {
            return new Integer(getCoursId());
        }
        if (name.equals(fr.iut2.sil4.data.CoursPeer.START_TIME))
        {
            return getStartTime();
        }
        if (name.equals(fr.iut2.sil4.data.CoursPeer.END_TIME))
        {
            return getEndTime();
        }
        if (name.equals(fr.iut2.sil4.data.CoursPeer.SALLE))
        {
            return getSalle();
        }
        if (name.equals(fr.iut2.sil4.data.CoursPeer.MATIERE_ID))
        {
            return new Integer(getMatiereId());
        }
        if (name.equals(fr.iut2.sil4.data.CoursPeer.ENSEIGNANT_ID))
        {
            return new Integer(getEnseignantId());
        }
        if (name.equals(fr.iut2.sil4.data.CoursPeer.GROUPE_ID))
        {
            return new Integer(getGroupeId());
        }
        return null;
    }

    /**
     * Set field values by Peer Field Name
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPeerName(String name, Object value)
        throws TorqueException, IllegalArgumentException
    {
        if (fr.iut2.sil4.data.CoursPeer.COURS_ID.getSqlExpression().equals(name))
        {
            return setByName("CoursId", value);
        }
        if (fr.iut2.sil4.data.CoursPeer.START_TIME.getSqlExpression().equals(name))
        {
            return setByName("StartTime", value);
        }
        if (fr.iut2.sil4.data.CoursPeer.END_TIME.getSqlExpression().equals(name))
        {
            return setByName("EndTime", value);
        }
        if (fr.iut2.sil4.data.CoursPeer.SALLE.getSqlExpression().equals(name))
        {
            return setByName("Salle", value);
        }
        if (fr.iut2.sil4.data.CoursPeer.MATIERE_ID.getSqlExpression().equals(name))
        {
            return setByName("MatiereId", value);
        }
        if (fr.iut2.sil4.data.CoursPeer.ENSEIGNANT_ID.getSqlExpression().equals(name))
        {
            return setByName("EnseignantId", value);
        }
        if (fr.iut2.sil4.data.CoursPeer.GROUPE_ID.getSqlExpression().equals(name))
        {
            return setByName("GroupeId", value);
        }
        return false;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
        if (pos == 0)
        {
            return new Integer(getCoursId());
        }
        if (pos == 1)
        {
            return getStartTime();
        }
        if (pos == 2)
        {
            return getEndTime();
        }
        if (pos == 3)
        {
            return getSalle();
        }
        if (pos == 4)
        {
            return new Integer(getMatiereId());
        }
        if (pos == 5)
        {
            return new Integer(getEnseignantId());
        }
        if (pos == 6)
        {
            return new Integer(getGroupeId());
        }
        return null;
    }

    /**
     * Set field values by its position (zero based) in the XML schema.
     *
     * @param position The field position
     * @param value field value
     * @return True if value was set, false if not (invalid position / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPosition(int position, Object value)
        throws TorqueException, IllegalArgumentException
    {
        if (position == 0)
        {
            return setByName("CoursId", value);
        }
        if (position == 1)
        {
            return setByName("StartTime", value);
        }
        if (position == 2)
        {
            return setByName("EndTime", value);
        }
        if (position == 3)
        {
            return setByName("Salle", value);
        }
        if (position == 4)
        {
            return setByName("MatiereId", value);
        }
        if (position == 5)
        {
            return setByName("EnseignantId", value);
        }
        if (position == 6)
        {
            return setByName("GroupeId", value);
        }
        return false;
    }



    /**
     * Stores an object in the database.  If the object is new,
     * it is inserted; otherwise an update is performed.
     *
     * @param toSave the object to be saved, not null.
     *
     * @throws TorqueException if an error occurs during saving.
     */
    public void save() throws TorqueException
    {
        save(CoursPeer.DATABASE_NAME);
    }

    /**
     * Stores an object in the database.  If the object is new,
     * it is inserted; otherwise an update is performed.
     *
     * @param toSave the object to be saved, not null.
     * @param dbName the name of the database to which the object
     *        should be saved.
     *
     * @throws TorqueException if an error occurs during saving.
     */
    public void save(String dbName) 
            throws TorqueException
    {
        Connection con = null;
        try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
    }

    /**
     * Stores an object in the database.  If the object is new,
     * it is inserted; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally.
     *
     * @param toSave the object to be saved, not null.
     * @param con the connection to use for saving the object, not null.
     *
     * @throws TorqueException if an error occurs during saving.
     */
    public void save(Connection con) 
            throws TorqueException
    {
        if (isSaving())
        {
            return;
        }
        try
        {
            setSaving(true);
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    CoursPeer.doInsert((Cours) this, con);
                    setNew(false);
                }
                else
                {
                    CoursPeer.doUpdate((Cours) this, con);
                }
            }

            if (isAbsencesInitialized())
            {
                for (Absence collAbsences : getAbsences())
                {
                    collAbsences.save(con);
                }
            }
        }
        finally
        {
            setSaving(false);
        }
    }




    /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param key coursId ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        
    {
        setCoursId(((NumberKey) key).intValue());
    }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) 
    {
        setCoursId(Integer.parseInt(key));
    }


    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
        return SimpleKey.keyFor(getCoursId());
    }


    /**
     * Returns an id that differentiates the referenced Matiere object
     * from all other Matiere objects.
     *
     * @return an ObjectKey.
     */
    public ObjectKey getForeignKeyForMatiere()
    {
        int foreignKey = getMatiereId();
        if (foreignKey == 0)
        {
            return SimpleKey.keyFor((Number) null);
        }
        return SimpleKey.keyFor(foreignKey);
    }
    /**
     * Returns an id that differentiates the referenced Enseignant object
     * from all other Enseignant objects.
     *
     * @return an ObjectKey.
     */
    public ObjectKey getForeignKeyForEnseignant()
    {
        int foreignKey = getEnseignantId();
        if (foreignKey == 0)
        {
            return SimpleKey.keyFor((Number) null);
        }
        return SimpleKey.keyFor(foreignKey);
    }
    /**
     * Returns an id that differentiates the referenced Groupe object
     * from all other Groupe objects.
     *
     * @return an ObjectKey.
     */
    public ObjectKey getForeignKeyForGroupe()
    {
        int foreignKey = getGroupeId();
        if (foreignKey == 0)
        {
            return SimpleKey.keyFor((Number) null);
        }
        return SimpleKey.keyFor(foreignKey);
    }

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     */
    public Cours copy() throws TorqueException
    {
        return copy(true);
    }

    /**
     * Makes a copy of this object using a connection.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     *
     * @param con the database connection to read associated objects.
     */
    public Cours copy(Connection con) throws TorqueException
    {
        return copy(true, con);
    }

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     */
    public Cours copy(boolean deepcopy) throws TorqueException
    {
        Cours cours = new Cours();

        return copyInto(cours, deepcopy);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     * @param con the database connection to read associated objects.
     */
    public Cours copy(boolean deepcopy, Connection con) throws TorqueException
    {
        Cours cours = new Cours();

        return copyInto(cours, deepcopy, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     */
    public Cours copyInto(Cours copyObj) throws TorqueException
    {
        return copyInto(copyObj, true);
    }

    /**
     * Fills the copyObj with the contents of this object using connection.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param con the database connection to read associated objects.
     */
    public Cours copyInto(Cours copyObj, Connection con) throws TorqueException
    {
        return copyInto(copyObj, true, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     */
    protected Cours copyInto(Cours copyObj, boolean deepcopy) throws TorqueException
    {
        copyObj.setCoursId(0);
        copyObj.setStartTime(startTime);
        copyObj.setEndTime(endTime);
        copyObj.setSalle(salle);
        copyObj.setMatiereId(matiereId);
        copyObj.setEnseignantId(enseignantId);
        copyObj.setGroupeId(groupeId);

        if (deepcopy)
        {
            if (collAbsences != null)
            {
                for (int i = 0; i < collAbsences.size(); i++)
                {
                    Absence obj = collAbsences.get(i);
                    copyObj.addAbsence(obj.copy());
                }
            }
            else
            {
                copyObj.collAbsences = null;
            }
        }
        return copyObj;
    }
        
    
    /**
     * Fills the copyObj with the contents of this object using connection.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     * @param con the database connection to read associated objects.
     */
    public Cours copyInto(Cours copyObj, boolean deepcopy, Connection con) throws TorqueException
    {
        copyObj.setCoursId(0);
        copyObj.setStartTime(startTime);
        copyObj.setEndTime(endTime);
        copyObj.setSalle(salle);
        copyObj.setMatiereId(matiereId);
        copyObj.setEnseignantId(enseignantId);
        copyObj.setGroupeId(groupeId);

        if (deepcopy)
        {
            for (Absence obj : getAbsences(con))
            {
                copyObj.addAbsence(obj.copy());
            }
        }
        return copyObj;
    }

    /** The Peer class */
    private static final fr.iut2.sil4.data.CoursPeer peer
            = new fr.iut2.sil4.data.CoursPeer();

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public fr.iut2.sil4.data.CoursPeer getPeer()
    {
        return peer;
    }

    /**
     * Retrieves the TableMap object related to this Table data without
     * compiler warnings of using getPeer().getTableMap().
     *
     * @return The associated TableMap object.
     */
    public TableMap getTableMap() throws TorqueException
    {
        return fr.iut2.sil4.data.CoursPeer.getTableMap();
    }



    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Cours:\n");
        str.append("coursId = ")
           .append(getCoursId())
           .append("\n");
        str.append("startTime = ")
           .append(getStartTime())
           .append("\n");
        str.append("endTime = ")
           .append(getEndTime())
           .append("\n");
        str.append("salle = ")
           .append(getSalle())
           .append("\n");
        str.append("matiereId = ")
           .append(getMatiereId())
           .append("\n");
        str.append("enseignantId = ")
           .append(getEnseignantId())
           .append("\n");
        str.append("groupeId = ")
           .append(getGroupeId())
           .append("\n");
        return(str.toString());
    }

    /**
     * Compares the primary key of this instance with the key of another.
     *
     * @param toCompare The object to compare to.
     * @return Whether the primary keys are equal and the object have the
     *         same class.
     */
    public boolean equals(Object toCompare)
    {
        if (toCompare == null)
        {
            return false;
        }
        if (this == toCompare)
        {
            return true;
        }
        if (!getClass().equals(toCompare.getClass()))
        {
            return false;
        }
        Cours other = (Cours) toCompare;
        if (getPrimaryKey() == null || other.getPrimaryKey() == null)
        {
            return false;
        }
        return getPrimaryKey().equals(other.getPrimaryKey());
    }

    /**
     * If the primary key is not <code>null</code>, return the hashcode of the
     * primary key.  Otherwise calls <code>Object.hashCode()</code>.
     *
     * @return an <code>int</code> value
     */
    public int hashCode()
    {
        ObjectKey ok = getPrimaryKey();
        if (ok == null)
        {
            return super.hashCode();
        }

        return ok.hashCode();
    }



    /**
     * Compares the content of this object to another object
     *
     * @param toCompare The object to compare to.
     * @return true if all of the columns in the other object have 
     *         the same value as the objects in this class.
     */
    public boolean valueEquals(Cours toCompare)
    {
        if (toCompare == null)
        {
            return false;
        }
        if (this == toCompare)
        {
            return true;
        }
        if (this.coursId != toCompare.getCoursId())
        {
            return false;
        }
        if (!ObjectUtils.equals(this.startTime, toCompare.getStartTime()))
        {
            return false;
        }
        if (!ObjectUtils.equals(this.endTime, toCompare.getEndTime()))
        {
            return false;
        }
        if (!ObjectUtils.equals(this.salle, toCompare.getSalle()))
        {
            return false;
        }
        if (this.matiereId != toCompare.getMatiereId())
        {
            return false;
        }
        if (this.enseignantId != toCompare.getEnseignantId())
        {
            return false;
        }
        if (this.groupeId != toCompare.getGroupeId())
        {
            return false;
        }
        return true;
    }



}
